package com.ghy.text;

import com.ghy.entity.EbNews;
import com.ghy.mapper.CommentMapper;
import com.ghy.entity.EbComment;
import org.apache.ibatis.annotations.Mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;


@RunWith(SpringJUnit4ClassRunner.class)
//导入 spring 的配置文件
@ContextConfiguration("classpath:xml/spring-dao.xml")
public class CommentTest {
    @Autowired
    CommentMapper commentMapper;
    @Test
    public void testCommentPage(){
        int page =1;//查询第 1 页
        int pageSize= 3;//每页 3 条
        // alt+Enter
        List<EbComment> comment = commentMapper.findByPage((page - 1) * pageSize, pageSize);
        System.out.println(comment);
    }
    @Test
    public void testCommentSave(){
        EbComment ebComment = new EbComment();
        ebComment.setEcContent("疯子");
        ebComment.setEcNickName("小齐");
        int num = commentMapper.save(ebComment);
        System.out.println("result-:"+num);
    }

    @Test
    public void testCommentUpdate(){
        EbComment ebComment = new EbComment();
        ebComment.setEcId(684);
        ebComment.setEcContent("今天心情真好");
        ebComment.setEcCreateTime("2010-12-10");
        ebComment.setEcNickName("小明");
        //调用更新的方法
        int result = commentMapper.updateByPrimaryKey(ebComment);
        System.out.println("result:"+result);
    }

    @Test
    public void testGetMaxPage(){
        Integer maxPage = commentMapper.getMaxPage(4);
        System.out.println("maxPage="+maxPage);
    }
    @Test
    public void testSelectOne(){
        System.out.println(commentMapper.selectOne(682) );
    }
    @Test
    public void testCommentDelete(){
        int result = commentMapper.remove(683);
        System.out.println("result:"+result);
    }
}